//
//  TestNSDate.m
//  OCDemo
//
//  Created by wxf on 2024/9/8.
//

#import "TestNSDate.h"

@implementation TestNSDate

- (void)test1 {
    NSDate *date = [NSDate date];
    NSLog(@"date = %@", date);
    
    //当前时间+1个小时
    NSDate *newDate = [date dateByAddingTimeInterval:1*60*60];
    NSLog(@"newDate = %@", newDate);
    //未来时间
    NSDate *futureDate = [NSDate distantFuture];
    NSLog(@"futureDate = %@", futureDate);
    
    //过去时间
    NSDate *distantPast = [NSDate distantPast];
    NSLog(@"distantPast = %@", distantPast); 
    
    
    //格式转换
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    formatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    //HH 24进制  hh 12进制
    NSString *dateStr = [formatter stringFromDate:date];
    NSLog(@"dateStr = %@", dateStr);
    
    //NSString -> NSDate
    NSDate *date1 = [formatter dateFromString:dateStr];
    NSLog(@"NSDate date1 = %@", date1);
    
    formatter.dateFormat = @"yyyy-MM-dd hh:mm:ss";
    NSLog(@"dateStr = %@", [formatter stringFromDate:date]);  
    
    
    formatter.dateFormat = @"yyyy-MM-dd";
    NSLog(@"dateStr = %@", [formatter stringFromDate:date]);

    formatter.dateFormat = @"MM-dd hh:mm:ss";
    NSLog(@"dateStr = %@", [formatter stringFromDate:date]);
    
    
    /*
     date = Sun Sep  8 21:20:14 2024
     newDate = Sun Sep  8 22:20:14 2024
     futureDate = Mon Jan  1 08:00:00 4001
     distantPast = Sat Dec 30 08:05:43 0000
     dateStr = 2024-09-08 21:20:14
     NSDate date1 = Sun Sep  8 21:20:14 2024
     dateStr = 2024-09-08 09:20:14
     dateStr = 2024-09-08
     dateStr = 09-08 09:20:14
     */
    

}

@end
